FROM 'certbot/certbot'

LABEL maintainer "iyinchao"

ENV TZ="Asian/Shanghai" \ 
    ALIYUN_REGION_ID="cn-hangzhou" \
    ALIYUN_DNS_ACCESS_KEY="***" \
    ALIYUN_DNS_ACCESS_KEY_SECRET="***" \ 
    CERTBOT_DOMAIN="*.example.com" \
    CERTBOT_EMAIL="admin@example.com"

USER root

# 安装一些工具
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
    apk add curl jq

# 安装 aliyun-cli
RUN wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz && \
    tar xzvf aliyun-cli-linux-latest-amd64.tgz && \
    cp aliyun /usr/local/bin && \
    rm aliyun && rm aliyun-cli-linux-latest-amd64.tgz

# 安装 cerbot-dns-aliyun 插件
RUN wget https://cdn.jsdelivr.net/gh/justjavac/certbot-dns-aliyun@main/alidns.sh && \
    cp alidns.sh /usr/local/bin && \
    chmod +x /usr/local/bin/alidns.sh && \
    ln -s /usr/local/bin/alidns.sh /usr/local/bin/alidns && \
    rm ./alidns.sh

WORKDIR /opt/service/
COPY *.sh .
RUN chmod +x *.sh

ENTRYPOINT [ "sh", "./entrypoint.sh" ]